<?php
declare (strict_types = 1);

namespace app\admin\controller;

use addons\Builder\facade\Builder;
use think\facade\View;
use app\common\tool\Result;
use think\response\Json;
//该文件为自动生成，请按需修改
class Cate extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Cate';

    public function index()
    {

        View::assign('list', $this->model::getAll());
        return View::fetch('cate/index');
    }

    public function edit($id = '', $pid = '', $tpl = '')
    {
        $p_title = '';
        if ($pid) {
            $p_title = $this->model::where('id', $pid)->value('title');
        }

        View::assign('p_title', $p_title);
        return parent::edit($id, 'cate/edit');
    }
    public function edit_cate()
    {
        $id = $this->request->param('id');
        $info = $this->model::find($id);
        View::assign('info', $info);
        return View::fetch('cate/edit_cate');
    }
    public function saveCate()
    {
        try {
            $param = $this->request->param();
            return Result::fastReturn($this->model::saveCate($param));
        }catch (\Exception $e) {
            return Result::fail($e->getMessage());
        }
    }
    public function getCate()
    {
        $id = $this->request->param('id', 0);
        return json($this->model::getCate($id));
    }
}
